package com.supkong.java.optional;

import com.supkong.java.optional.bean.Role;
import com.supkong.java.optional.bean.User;

/**
 * @program: jdk8-learning-example
 * @author: Kong
 * @create: 2019-10-31 18:00
 * @description:
 **/
public class UserService {

    private RoleDao roleDao = new RoleDao();
    /**
     * 我们平常的做法
     * @param user
     */
    public String bindUserRole(User user){
        if(null == user){
            return null;
        }
        String roleId = user.getRoleId();
        if(null == roleId){
            return  null;
        }
        Role role = roleDao.selectOne(roleId);
        if(null != role){
            role.setUserId(user.getId());
            roleDao.save(role);
        }
        return  roleId;
    }
}
